#! /usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# version number of the defaults package
VDEF	:= $(strip $(shell dpkg-parsechangelog | awk -F: '/^Version:/ {print $$NF}'))

VMAJOR	:= $(shell echo $(VDEF) | awk -F. '{print $$1}')
VMINOR	:= $(shell echo $(VDEF) | awk -F. '{print $$2}' | sed -e 's/\([0-9]*\).*/\1/')
REL_EXT	:= $(shell echo $(VDEF) | sed -e 's/^$(VMAJOR)\.$(VMINOR)//')

# gcc-defaults 0.8 is the first version for 2.95.4.
REL_NO_295	:= $(shell expr $(VMINOR) + 15)$(REL_EXT)
# gcc-defaults 0.6 is the first version with 2.96 support.
REL_NO_296	:= $(shell expr $(VMINOR) + 17)$(REL_EXT)
# gcc-defaults 0.17 is the first version with 3.0.4 support.
REL_NO_30	:= $(shell expr $(VMINOR) + 6)$(REL_EXT)
# gcc-defaults 1.0 is the first version with 3.1 support.
REL_NO_31	:= $(shell expr $(VMINOR) + 1)$(REL_EXT)
# gcc-defaults 1.2 is the first version with 3.2 support.
REL_NO_32	:= $(shell expr $(VMINOR) - 1)$(REL_EXT)
# gcc-defaults 1.3 is the first version with 3.2.2 support.
REL_NO_322	:= $(shell expr $(VMINOR) - 3)$(REL_EXT)
# gcc-defaults 1.4 is the first version with 3.2.3 support.
REL_NO_323	:= $(shell expr $(VMINOR) - 4)$(REL_EXT)
# gcc-defaults 1.5 is the first version with 3.3 support.
REL_NO_33	:= $(shell expr $(VMINOR) - 5)$(REL_EXT)
# gcc-defaults 1.7 is the first version with 3.3.1 support.
REL_NO_331	:= $(shell expr $(VMINOR) - 7)$(REL_EXT)
# gcc-defaults 1.10 is the first version with 3.3.2 support.
REL_NO_332	:= $(shell expr $(VMINOR) - 9)$(REL_EXT)
# gcc-defaults 1.13 is the first version with 3.3.3 support.
REL_NO_333	:= $(shell expr $(VMINOR) - 12)$(REL_EXT)
# gcc-defaults 1.16 is the first version with 3.3.4 support.
REL_NO_334	:= $(shell expr $(VMINOR) - 15)$(REL_EXT)
# gcc-defaults 1.19 is the first version with 3.3.5 support.
REL_NO_335	:= $(shell expr $(VMINOR) - 18)$(REL_EXT)
# gcc-defaults 1.22 is the first version with 3.3.6 support.
REL_NO_336     := $(shell expr $(VMINOR) - 21)$(REL_EXT)

# gcc-defaults 1.22 is the first version with 3.4.3 support.
REL_NO_343	:= $(shell expr $(VMINOR) - 21)$(REL_EXT)
# gcc-defaults 1.23 is the first version with 3.4.4 support.
REL_NO_344	:= $(shell expr $(VMINOR) - 23)$(REL_EXT)
# gcc-defaults 1.30 is the first version with 3.4.5 support.
REL_NO_345	:= $(shell expr $(VMINOR) - 29)$(REL_EXT)
# gcc-defaults 1.32 is the first version with 3.4.5 support.
REL_NO_346	:= $(shell expr $(VMINOR) - 31)$(REL_EXT)

# gcc-defaults 1.23 is the first version with 4.0.0 support.
REL_NO_400	:= $(shell expr $(VMINOR) - 22)$(REL_EXT)
# gcc-defaults 1.26 is the first version with 4.0.1 support.
REL_NO_401	:= $(shell expr $(VMINOR) - 25)$(REL_EXT)
# gcc-defaults 1.29 is the first version with 4.0.2 support.
REL_NO_402	:= $(shell expr $(VMINOR) - 28)$(REL_EXT)
# gcc-defaults 1.32 is the first version with 4.0.3 support.
REL_NO_403	:= $(shell expr $(VMINOR) - 31)$(REL_EXT)

# gcc-defaults 1.33 is the first version with 4.1.0 support.
REL_NO_410	:= $(shell expr $(VMINOR) - 33)$(REL_EXT)
# gcc-defaults 1.36 is the first version with 4.1.1 support.
REL_NO_411	:= $(shell expr $(VMINOR) - 35)$(REL_EXT)
# gcc-defaults 1.51 is the first version with 4.1.2 support.
REL_NO_412	:= $(shell expr $(VMINOR) - 50)$(REL_EXT)

# gcc-defaults 1.54 is the first version with 4.2.0 support.
REL_NO_420	:= $(shell expr $(VMINOR) - 54)$(REL_EXT)
# gcc-defaults 1.56 is the first version with 4.2.1 support.
REL_NO_421	:= $(shell expr $(VMINOR) - 55)$(REL_EXT)
# gcc-defaults 1.62 is the first version with 4.2.2 support.
REL_NO_422	:= $(shell expr $(VMINOR) - 61)$(REL_EXT)
# gcc-defaults 1.63 is the first version with 4.2.3 support.
REL_NO_423	:= $(shell expr $(VMINOR) - 62)$(REL_EXT)
# gcc-defaults 1.73 is the first version with 4.2.4 support.
REL_NO_424	:= $(shell expr $(VMINOR) - 72)$(REL_EXT)

# gcc-defaults 1.63 is the first version with 4.3 support.
REL_NO_43	:= $(shell expr $(VMINOR) - 62)$(REL_EXT)
# gcc-defaults 1.66 is the first version with 4.3 support.
REL_NO_430	:= $(shell expr $(VMINOR) - 65)$(REL_EXT)
# gcc-defaults 1.74 is the first version with 4.3.1 support.
REL_NO_431	:= $(shell expr $(VMINOR) - 73)$(REL_EXT)
# gcc-defaults 1.76 is the first version with 4.3.2 support.
REL_NO_432	:= $(shell expr $(VMINOR) - 75)$(REL_EXT)
# gcc-defaults 1.79 is the first version with 4.3.3 support.
REL_NO_433	:= $(shell expr $(VMINOR) - 78)$(REL_EXT)
# gcc-defaults 1.88 is the first version with 4.3.4 support.
REL_NO_434	:= $(shell expr $(VMINOR) - 87)$(REL_EXT)
# gcc-defaults 1.81 is the first version with 4.4.0 support.
REL_NO_440	:= $(shell expr $(VMINOR) - 80)$(REL_EXT)
# gcc-defaults 1.88 is the first version with 4.4.1 support.
REL_NO_441	:= $(shell expr $(VMINOR) - 87)$(REL_EXT)
# gcc-defaults 1.90 is the first version with 4.4.2 support.
REL_NO_442	:= $(shell expr $(VMINOR) - 89)$(REL_EXT)

GPC_VERSION	:= 2.1
GDC_VERSION	:= 0.25

# minimum required gcc-X.Y versions
REQV_295	:= (>= 1:2.95.4-16)
REQV_296	:= 
REQV_30		:= (>= 1:3.0.4-12)
REQV_32		:= (>= 1:3.2.3-1)
REQV_33		:= (>= 1:3.3.6-1)
REQV_GPC_33	:= (>= 1:3.3.6.$(GPC_DATE)-1)
REQV_34		:= (>= 3.4.6-1)
REQV_40		:= (>= 4.0.3-1)
REQV_41		:= (>= 4.1.2-1)
REQV_41_GCJ	:= (>= 4.1.2-1)
REQV_41_GPC	:= (>= $(GPC_VERSION)-4.1.2-16)
REQV_41_GDC	:= (>= $(GDC_VERSION)-4.1.2-18)
REQV_42		:= (>= 4.2.1-0maemo1)
REQV_42_GCJ	:= (>= 4.2.1-0maemo1)
REQV_43		:= (>= 4.3.3-0maemo1)
REQV_44		:= (>= 4.4.1-0maemo1)

REQV_LIBGCJ_BC	:= (>= 4.4.1-0maemo1)

# architecture dependent variables
DEB_HOST_ARCH		:= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_GNU_TYPE	:= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

# gcj-4.4 has some regressions in the testsuite compared to 4.3
# results on alpha are bad in both 4.3 and 4.4.
gcj44_archs = amd64 hppa hurd-i386 lpia mips mipsel powerpc ppc64 kfreebsd-amd64 kfreebsd-i386 sh4

# CV_XXX is the complete version number, including the release, without epoch
CV_CHILL:= 2.95.4-$(REL_NO_295)
CV_GPC	:= 3.4.6-$(REL_NO_346)

CV_CPP		:= 4.4.1-$(REL_NO_441)
CV_GCC		:= 4.4.1-$(REL_NO_441)
CV_GPP		:= 4.4.1-$(REL_NO_441)
CV_GOBJC	:= 4.4.1-$(REL_NO_441)
CV_GOBJCXX	:= 4.4.1-$(REL_NO_441)
CV_GFORT	:= 4.4.1-$(REL_NO_441)
CV_GCJ		:= 4.4.1-$(REL_NO_441)
CV_GIJ		:= 4.4.1-$(REL_NO_441)
CV_LIBGCJBC	:= 4.4.1-$(REL_NO_441)
CV_GPC		:= $(GPC_VERSION)-4.1.2-$(REL_NO_412)
CV_GDC		:= 4.1.2-$(REL_NO_412)
CV_LIBGCJCOMMON	:= 1:4.4.1-$(REL_NO_441)
CV_SPU		:= 4.4.1-$(REL_NO_441)

#ifneq (,$(filter $(DEB_HOST_ARCH), $(gcj44_archs)))
#  CV_GCJ		:= 4.4.2-$(REL_NO_442)
#  CV_GIJ		:= 4.4.2-$(REL_NO_442)
#  CV_LIBGCJBC		:= 4.4.2-$(REL_NO_442)
#endif

REQV_CHILL	= $(REQV_295)
REQV_GPC	= $(REQV_34)

REQV_CPP	= $(REQV_44)
REQV_GCC	= $(REQV_44)
REQV_GPP	= $(REQV_44)
REQV_GOBJC	= $(REQV_44)
REQV_GOBJCXX	= $(REQV_44)
REQV_GFORT	= $(REQV_44)
REQV_GCJ	= $(REQV_44)
REQV_GIJ	= $(REQV_44)
REQV_GPC	= $(REQV_41_GPC)
REQV_GDC	= $(REQV_41_GDC)
REQV_SPU	= $(REQV_44)

EPOCH=4
EPOCH_GPC=5
OS_NAME	:= Linux
distribution := $(shell lsb_release -is)
all_packages    := g++ gfortran gcj gobjc gobjc++ gpc gdc
all_packages	+= gcc-spu g++-spu gfortran-spu
no_packages	:= chill

lib32 = /usr/lib32

LIBGCJ	= libgcj10
LIBGCJ_PC	= libgcj10.pc
LIBGCJ_SONAME	= 10

gcj_archs = alpha amd64 hppa ia64 lpia m68k mips mipsel powerpc ppc64 s390 sh4 sparc kfreebsd-amd64 kfreebsd-i386 hurd-i386
gcj_native_archs = alpha amd64 hppa ia64 lpia mips mipsel powerpc ppc64 s390 sh4 sparc kfreebsd-amd64 kfreebsd-i386 hurd-i386
multilib_archs = amd64 kfreebsd-amd64 mips mipsel powerpc ppc64 s390 sparc

ifneq (,$(filter $(DEB_HOST_ARCH), $(multilib_archs)))
  with_multilib = yes
endif

with_gfdl_docs := no
ifeq ($(distribution),Ubuntu)
  with_gfdl_docs := yes
endif

java_no_archs := arm 
ifneq (,$(filter $(DEB_HOST_ARCH),$(java_no_archs)))
  no_packages += gcj gij libgcj-bc gcj-jre-headless gcj-jre gcj-jdk
endif

gpc_no_archs := sh3 sh4
ifneq (,$(filter $(DEB_HOST_ARCH),$(gpc_no_archs)))
  no_packages += gpc gpc-doc
endif

gdc_no_archs := sparc hurd-i386
ifneq (,$(filter $(DEB_HOST_ARCH),$(gdc_no_archs)))
  no_packages += gdc
endif

ifeq ($(DEB_HOST_ARCH),hurd-i386)
    OS_NAME	:= Hurd
endif

ifneq (,$(filter $(DEB_HOST_ARCH),kfreebsd-i386 kfreebsd-amd64))
    OS_NAME	:= kFreeBSD
endif

ifeq ($(DEB_HOST_ARCH),netbsd-i386)
    OS_NAME	:= NetBSD
endif

ifeq (,$(filter $(DEB_HOST_ARCH),powerpc ppc64))
    no_packages += gcc-spu g++-spu gfortran-spu
endif

ifneq ($(with_gfdl_docs),yes)
    no_packages := $(sort $(no_packages) cpp-doc gcc-doc gfortran-doc)
endif

packages := $(filter-out $(no_packages), $(all_packages))

# derived version number (without release)
V_CPP	:= $(shell echo $(CV_CPP)   | sed 's/-[^-]*$$//')
V_GCC	:= $(shell echo $(CV_GCC)   | sed 's/-[^-]*$$//')
V_GPP	:= $(shell echo $(CV_GPP)   | sed 's/-[^-]*$$//')
V_GOBJC	:= $(shell echo $(CV_GOBJC) | sed 's/-[^-]*$$//')
V_GOBJCXX	:= $(shell echo $(CV_GOBJCXX) | sed 's/-[^-]*$$//')
V_GFORT	:= $(shell echo $(CV_GFORT) | sed 's/-[^-]*$$//')
V_CHILL	:= $(shell echo $(CV_CHILL) | sed 's/-[^-]*$$//')
V_GCJ	:= $(shell echo $(CV_GCJ)   | sed 's/-[^-]*$$//')
V_GIJ	:= $(shell echo $(CV_GIJ)   | sed 's/-[^-]*$$//')
ifneq (,$(CV_GCJ_HACKED))
  V_GCJ	:= $(shell echo $(CV_GCJ_HACKED)   | sed 's/-[^-]*$$//')
  V_GIJ	:= $(shell echo $(CV_GIJ_HACKED)   | sed 's/-[^-]*$$//')
endif
V_GPC	:= $(shell echo $(CV_GPC)   | sed 's/$(GPC_VERSION)-//;s/-[^-]*$$//')
V_GDC	:= $(shell echo $(CV_GDC)   | sed 's/-[^-]*$$//')
V_SPU	:= $(shell echo $(CV_SPU)   | sed 's/-[^-]*$$//')

# number for the package name
PV_CPP	:= $(shell echo $(V_CPP)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GCC	:= $(shell echo $(V_GCC)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GDC	:= $(shell echo $(V_GDC)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GPP	:= $(shell echo $(V_GPP)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GOBJC:= $(shell echo $(V_GOBJC) | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GOBJCXX:= $(shell echo $(V_GOBJCXX) | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GFORT:= $(shell echo $(V_GFORT) | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_CHILL:= $(shell echo $(V_CHILL) | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GCJ	:= $(shell echo $(V_GCJ)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GIJ	:= $(shell echo $(V_GIJ)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_GPC	:= $(shell echo $(V_GPC)   | awk -F. '{printf "%d.%d", $$1, $$2}')
PV_SPU	:= $(shell echo $(V_SPU)   | awk -F. '{printf "%d.%d", $$1, $$2}')

README:
	m4 -DPACKAGES="$(packages)" \
	   -DOS_NAME=$(OS_NAME) \
	   -DDEB_ARCH=$(DEB_HOST_ARCH) \
	   -DV_CPP=$(V_CPP)     -DPV_CPP=$(PV_CPP) \
	   -DV_GCC=$(V_GCC)     -DPV_GCC=$(PV_GCC) \
	   -DV_GPP=$(V_GPP)     -DPV_GPP=$(PV_GPP) \
	   -DV_GOBJC=$(V_GOBJC) -DPV_GOBJC=$(PV_GOBJC) \
	   -DV_GOBJCXX=$(V_GOBJCXX) -DPV_GOBJCXX=$(PV_GOBJCXX) \
	   -DV_CHILL=$(V_CHILL) -DPV_CHILL=$(PV_CHILL) \
	   -DV_GFORT=$(V_GFORT) -DPV_GFORT=$(PV_GFORT) \
	   -DV_GCJ=$(V_GCJ)     -DPV_GCJ=$(PV_GCJ) \
	   -DV_GIJ=$(V_GIJ)     -DPV_GIJ=$(PV_GIJ) \
	   -DV_GPC=$(V_GPC)     -DPV_GPC=$(PV_GPC) \
	   -DV_GDC=$(V_GDC)     -DPV_GDC=$(PV_GDC) \
	   -DV_SPU=$(V_SPU)     -DPV_SPU=$(PV_SPU) \
	   $(if $(filter yes,$(with_gfdl_docs)), -DGFDL) \
		debian/README.Debian.m4 > debian/README.Debian.tmp2
	uniq debian/README.Debian.tmp2 > debian/README.Debian.tmp
	rm -f debian/README.Debian.tmp2
	[ -e debian/README.Debian ] \
	  && cmp -s debian/README.Debian debian/README.Debian.tmp \
	  && rm -f debian/README.Debian.tmp && exit 0; \
	  mv debian/README.Debian.tmp debian/README.Debian

substvars:
	( \
	  echo 'version:cpp=$(EPOCH):$(CV_CPP)'; \
	  echo 'version:gcc=$(EPOCH):$(CV_GCC)'; \
	  echo 'version:gpp=$(EPOCH):$(CV_GPP)'; \
	  echo 'version:gobjc=$(EPOCH):$(CV_GOBJC)'; \
	  echo 'version:gij=$(EPOCH):$(CV_GIJ)'; \
	  echo 'version:gcj=$(EPOCH):$(CV_GCJ)'; \
	  echo 'version:gpc=$(EPOCH_GPC):$(CV_GPC)'; \
	  echo 'version:gfort=$(EPOCH):$(CV_GFORT)'; \
	  echo 'version:libgcjcommon=$(CV_LIBGCJCOMMON)'; \
	  echo 'pv:cpp=$(PV_CPP)'; \
	  echo 'pv:gcc=$(PV_GCC)'; \
	  echo 'pv:gpp=$(PV_GPP)'; \
	  echo 'pv:gobjc=$(PV_GOBJC)'; \
	  echo 'pv:gobjcxx=$(PV_GOBJCXX)'; \
	  echo 'pv:chill=$(PV_CHILL)'; \
	  echo 'pv:gfort=$(PV_GFORT)'; \
	  echo 'pv:gcj=$(PV_GCJ)'; \
	  echo 'pv:gij=$(PV_GIJ)'; \
	  echo 'pv:gpc=$(PV_GPC)'; \
	  echo 'pv:gdc=$(PV_GDC)'; \
	  echo 'pv:spu=$(PV_SPU)'; \
	  echo 'reqv:cpp=$(REQV_CPP)'; \
	  echo 'reqv:gcc=$(REQV_GCC)'; \
	  echo 'reqv:gpp=$(REQV_GPP)'; \
	  echo 'reqv:gobjc=$(REQV_GOBJC)'; \
	  echo 'reqv:gobjcxx=$(REQV_GOBJCXX)'; \
	  echo 'reqv:chill=$(REQV_CHILL)'; \
	  echo 'reqv:gfort=$(REQV_GFORT)'; \
	  echo 'reqv:gcj=$(REQV_GCJ)'; \
	  echo 'reqv:gij=$(REQV_GIJ)'; \
	  echo 'reqv:gpc=$(REQV_GPC)'; \
	  echo 'reqv:gdc=$(REQV_GDC)'; \
	  echo 'reqv:spu=$(REQV_SPU)'; \
	  echo 'pkg:libgcj=$(LIBGCJ)'; \
	  echo 'pkg:libgcjawt=$(LIBGCJ)-awt'; \
	  echo 'version:libgcjbc=$(CV_LIBGCJBC)'; \
	) > debian/substvars.local
ifeq ($(with_multilib),yes)
	( \
	  echo 'pkgmulti:gcc=gcc-multilib'; \
	  echo 'pkgmulti:gpp=g++-multilib'; \
	  echo 'pkgmulti:gobjc=gobjc-multilib'; \
	  echo 'pkgmulti:gobjcxx=gobjc++-multilib'; \
	  echo 'pkgmulti:gfort=gfortran-multilib'; \
	) >> debian/substvars.local
endif
#ifneq (,$(filter $(DEB_HOST_ARCH), $(gcj44_archs)))
	( \
	  echo 'dep:jrehl=gcj-$${pv:gij}-jre-headless $${reqv:gij}'; \
	  echo 'dep:jre=gcj-$${pv:gij}-jre $${reqv:gij}'; \
	  echo 'dep:jdk=gcj-$${pv:gcj}-jdk $${reqv:gcj}'; \
	  echo 'pkg:gjdoc=gjdoc'; \
	  echo 'ver:gcjconflict=4:4.4.0-2'; \
	) >> debian/substvars.local
#else
#	( \
#	  echo 'dep:jrehl=java-gcj-compat-headless (>= 1.0.80), gij-$${pv:gij} $${reqv:gij}'; \
#	  echo 'dep:jre=java-gcj-compat (>= 1.0.80)'; \
#	  echo 'dep:jdk=java-gcj-compat-dev (>= 1.0.80), gcj-$${pv:gcj} $${reqv:gcj}'; \
#	  echo 'ver:gcjconflict=4:4.3.3-6'; \
#	) >> debian/substvars.local
#endif

build: README build-stamp
build-stamp:
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f *-stamp
	rm -rf build
	rm -f debian/control.tmp*
	rm -f debian/substvars.local
	rm -f debian/lib*gcj-bc.shlibs
	rm -f debian/gcc.postinst debian/g++.postinst debian/gfortran.postinst
	rm -f debian/generate-cacerts.pl
	rm -f debian/dh_nativejava.1
	dh_clean

install: build substvars
	dh_testdir
	dh_testroot
	dh_clean -k

	for p in `dh_listpackages`; do \
	  cp -l debian/substvars.local debian/$$p.substvars; \
	done

	: # cpp
	dh_installdirs -pcpp \
		lib usr/bin \
		usr/share/man/man1 usr/share/man/man7 usr/share/doc/cpp
	dh_link -pcpp \
	  /usr/bin/cpp-$(PV_CPP) /usr/bin/cpp \
	  /usr/bin/cpp-$(PV_CPP) /usr/bin/$(DEB_HOST_GNU_TYPE)-cpp

  ifeq ($(with_gfdl_docs),yes)
	for i in gfdl.7 gpl.7 fsf-funding.7; do \
	  cp -p $$i debian/cpp/usr/share/man/man7/$${i}gcc; \
	done
	dh_link -pcpp \
	  /usr/share/man/man1/cpp-$(PV_CPP).1.gz /usr/share/man/man1/cpp.1.gz \
	  /usr/share/man/man1/cpp-$(PV_CPP).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-cpp.1.gz

	: # cpp-doc
	dh_installdirs -pcpp-doc \
		usr/share/doc usr/share/info
	dh_link -pcpp-doc \
	  /usr/share/doc/gcc-$(PV_CPP)-base/cpp.html /usr/share/doc/cpp-doc/cpp.html \
	  /usr/share/doc/gcc-$(PV_CPP)-base/cppinternals.html /usr/share/doc/cpp-doc/cppinternals.html \
	  /usr/share/info/cpp-$(PV_CPP).info.gz /usr/share/info/cpp.info.gz \
	  /usr/share/info/cppinternals-$(PV_CPP).info.gz /usr/share/info/cppinternals.info.gz
  endif

	: # gcc
	dh_installdirs -pgcc usr/bin usr/share/man/man1 usr/share/doc
	dh_link -pgcc \
	  /usr/share/doc/cpp /usr/share/doc/gcc \
	  /usr/bin/gcc-$(PV_GCC) /usr/bin/gcc \
	  /usr/bin/gcc-$(PV_GCC) /usr/bin/$(DEB_HOST_GNU_TYPE)-gcc \
	  /usr/bin/gcov-$(PV_GCC) /usr/bin/gcov \
	  /usr/share/doc/gcc-$(PV_GCC)/README.Bugs /usr/share/doc/cpp/README.Bugs
ifeq ($(DEB_HOST_ARCH),sparc)
	rm -f debian/gcc/usr/bin/gcc
	$(CC) -DGCC_NAME=gcc-$(PV_GCC) -O2 -Wall sparc-gcc.c -o debian/gcc/usr/bin/gcc
	mkdir -p debian/gcc/etc
	cp -p debian/disable_64_gcc debian/gcc/etc/.
endif
	install -m 755 -p c89 debian/gcc/usr/bin/c89-gcc
	install -m 644 -p c89.1 debian/gcc/usr/share/man/man1/c89-gcc.1
	install -m 755 -p c99 debian/gcc/usr/bin/c99-gcc
	install -m 644 -p c99.1 debian/gcc/usr/share/man/man1/c99-gcc.1
	sed 's/@VER@/$(PV_GCC)/g' c99.1 > debian/gcc/usr/share/man/man1/c99-gcc.1

	sed -e 's/@GFDL@/$(if $(filter-out yes,$(with_gfdl_docs)),\#)/g' \
		debian/gcc.postinst.in > debian/gcc.postinst

  ifeq ($(with_gfdl_docs),yes)
	dh_link -pgcc \
	  /usr/share/man/man1/gcc-$(PV_GCC).1.gz /usr/share/man/man1/gcc.1.gz \
	  /usr/share/man/man1/gcc-$(PV_GCC).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-gcc.1.gz \
	  /usr/share/man/man1/gcov-$(PV_GCC).1.gz /usr/share/man/man1/gcov.1.gz 

	: # gcc-doc
	dh_installdirs -pgcc-doc \
		usr/share/doc usr/share/info
	dh_link -pgcc-doc \
	  /usr/share/doc/gcc-$(PV_GCC)-base/gcc.html /usr/share/doc/gcc-doc/gcc.html \
	  /usr/share/doc/gcc-$(PV_GCC)-base/gccint.html /usr/share/doc/gcc-doc/gccint.html \
	  /usr/share/doc/gcc-$(PV_GCC)-base/libgomp.html /usr/share/doc/gcc-doc/libgomp.html \
	  /usr/share/info/gcc-$(PV_GCC).info.gz /usr/share/info/gcc.info.gz \
	  /usr/share/info/gccint-$(PV_GCC).info.gz /usr/share/info/gccint.info.gz \
	  /usr/share/info/libgomp-$(PV_GCC).info.gz /usr/share/info/libgomp.info.gz 
  endif

ifneq (,$(filter gdc, $(packages)))
	: # gdc
	dh_installdirs -pgdc \
	  usr/share/doc usr/bin usr/share/man/man1
	dh_installdocs -pgdc debian/README.Debian

	# gdc binaries
	dh_link -pgdc \
		/usr/bin/gdc-$(PV_GDC) /usr/bin/gdc \
		/usr/bin/gdc-$(PV_GDC) /usr/bin/$(DEB_HOST_GNU_TYPE)-gdc-$(PV_GDC) \
		/usr/bin/gdc-$(PV_GDC) /usr/bin/$(DEB_HOST_GNU_TYPE)-gdc
	# gdmd binaries
	dh_link -pgdc \
		/usr/bin/gdmd-$(PV_GDC) /usr/bin/gdmd \
		/usr/bin/gdmd-$(PV_GDC) /usr/bin/$(DEB_HOST_GNU_TYPE)-gdmd-$(PV_GDC) \
		/usr/bin/gdmd-$(PV_GDC) /usr/bin/$(DEB_HOST_GNU_TYPE)-gdmd
	# manpages
	dh_link -pgdc \
		/usr/share/man/man1/gdc-$(PV_GDC).1.gz /usr/share/man/man1/gdc.1.gz \
		/usr/share/man/man1/gdc-$(PV_GDC).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-gdc.1.gz \
		/usr/share/man/man1/gdmd-$(PV_GDC).1.gz /usr/share/man/man1/gdmd.1.gz \
		/usr/share/man/man1/gdmd-$(PV_GDC).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-gdmd.1.gz
endif

ifneq (,$(filter gobjc, $(packages)))
	: # gobjc
	dh_installdirs -pgobjc usr/share/doc
	dh_link -pgobjc \
	  /usr/share/doc/cpp /usr/share/doc/gobjc
endif

ifneq (,$(filter gobjc++, $(packages)))
	: # gobjc++
	dh_installdirs -pgobjc++ usr/share/doc
	dh_link -pgobjc++ \
	  /usr/share/doc/cpp /usr/share/doc/gobjc++
endif

ifneq (,$(filter g++, $(packages)))
	: # g++
	dh_installdirs -pg++ usr/bin /usr/share/man/man1 usr/share/doc
	dh_link -pg++ \
	  /usr/share/doc/cpp /usr/share/doc/g++ \
	  /usr/bin/g++-$(PV_GPP) /usr/bin/g++ \
	  /usr/bin/g++-$(PV_GPP) /usr/bin/$(DEB_HOST_GNU_TYPE)-g++
  ifeq ($(DEB_HOST_ARCH),sparc)
	rm -f debian/g++/usr/bin/g++
	$(CC) -DGPP_NAME=g++-$(PV_GPP) -O2 -Wall sparc-g++.c -o debian/g++/usr/bin/g++
  endif
  ifeq ($(with_gfdl_docs),yes)
	dh_link -pg++ \
	  /usr/share/man/man1/g++-$(PV_GPP).1.gz /usr/share/man/man1/g++.1.gz \
	  /usr/share/man/man1/g++-$(PV_GPP).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-g++.1.gz
  endif
	sed -e 's/@GFDL@/$(if $(filter-out yes,$(with_gfdl_docs)),\#)/g' \
		debian/g++.postinst.in > debian/g++.postinst
endif

ifneq (,$(filter gfortran, $(packages)))
	: # gfortran
	dh_installdirs -pgfortran usr/bin /usr/share/man/man1 usr/share/doc
	dh_link -pgfortran \
	  /usr/share/doc/cpp /usr/share/doc/gfortran \
	  /usr/bin/gfortran-$(PV_GFORT) /usr/bin/gfortran \
	  /usr/bin/gfortran-$(PV_GFORT) /usr/bin/$(DEB_HOST_GNU_TYPE)-gfortran

ifneq (,$(filter $(DEB_HOST_ARCH), alpha))
	: # keep these as long as gcc version != gfortran version
	dh_link -pgfortran \
	  /usr/lib/gcc/$(DEB_HOST_GNU_TYPE)/4.3/libgfortran.so /usr/lib/libgfortran.so \
	  /usr/lib/gcc/$(DEB_HOST_GNU_TYPE)/4.3/libgfortran.a /usr/lib/libgfortran.a \
	  /usr/lib/gcc/$(DEB_HOST_GNU_TYPE)/4.3/libgfortranbegin.a /usr/lib/libgfortranbegin.a
  ifneq (,$(filter $(DEB_HOST_ARCH), amd64))
	dh_link -pgfortran-multilib \
	  /usr/lib/gcc/$(DEB_HOST_GNU_TYPE)/4.3/32/libgfortran.so $(lib32)/libgfortran.so \
	  /usr/lib/gcc/$(DEB_HOST_GNU_TYPE)/4.3/32/libgfortran.a $(lib32)/libgfortran.a \
	  /usr/lib/gcc/$(DEB_HOST_GNU_TYPE)/4.3/32/libgfortranbegin.a $(lib32)/libgfortranbegin.a
  endif
endif

  ifeq ($(with_gfdl_docs),yes)
	dh_link -pgfortran \
	  /usr/share/man/man1/gfortran-$(PV_GFORT).1.gz /usr/share/man/man1/gfortran.1.gz \
	  /usr/share/man/man1/gfortran-$(PV_GFORT).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-gfortran.1.gz

	: # gfortran-doc
	dh_installdirs -pgfortran-doc \
		usr/share/doc usr/share/info
	dh_link -pgfortran-doc \
	  /usr/share/doc/gcc-$(PV_GFORT)-base/fortran/gfortran.html \
	    /usr/share/doc/gfortran-doc/fortran/gfortran.html \
	  /usr/share/info/gfortran-$(PV_GFORT).info.gz /usr/share/info/gfortran.info.gz
  endif
	sed -e 's/@GFDL@/$(if $(filter-out yes,$(with_gfdl_docs)),\#)/g' \
		debian/gfortran.postinst.in > debian/gfortran.postinst
endif

ifeq (chill, $(findstring chill, $(packages)))
	: # chill
	dh_installdirs -pchill usr/bin /usr/share/man/man1 usr/share/doc
	dh_link -pchill \
	  /usr/share/doc/cpp /usr/share/doc/chill \
	  /usr/bin/chill-$(PV_CHILL) /usr/bin/chill
endif

ifneq (,$(filter gcj, $(packages)))
	: # gcj-jre-headless
	dh_installdirs -pgcj-jre-headless usr/bin /usr/share/man/man1 usr/share/doc
	dh_link -pgcj-jre-headless \
	  /usr/share/doc/libgcj-common /usr/share/doc/gcj-jre-headless \
	  /usr/bin/gij-$(PV_GIJ) /usr/bin/gij \
	  /usr/bin/gcj-dbtool-$(PV_GIJ) /usr/bin/gcj-dbtool \
	  /usr/bin/gkeytool-$(PV_GIJ) /usr/bin/gkeytool \
	  /usr/bin/gorbd-$(PV_GIJ) /usr/bin/gorbd \
	  /usr/bin/grmid-$(PV_GIJ) /usr/bin/grmid \
	  /usr/bin/grmiregistry-$(PV_GIJ) /usr/bin/grmiregistry \
	  /usr/bin/gserialver-$(PV_GIJ) /usr/bin/gserialver \

	: # gcj
	dh_installdirs -pgcj usr/bin /usr/share/man/man1 usr/share/doc
	dh_link -pgcj-jdk \
	  /usr/share/doc/cpp /usr/share/doc/gcj-jdk \
	  /usr/bin/gjavah-$(PV_GCJ) /usr/bin/gjavah \
	  /usr/bin/gcj-$(PV_GCJ) /usr/bin/gcj \
	  /usr/bin/gcj-$(PV_GCJ) /usr/bin/$(DEB_HOST_GNU_TYPE)-gcj \
	  /usr/bin/gcjh-$(PV_GCJ) /usr/bin/gcjh \
	  /usr/bin/gjar-$(PV_GCJ) /usr/bin/gjar \
	  /usr/bin/gjarsigner-$(PV_GCJ) /usr/bin/gjarsigner \
	  /usr/bin/grmic-$(PV_GCJ) /usr/bin/grmic \
	  /usr/bin/jv-convert-$(PV_GCJ) /usr/bin/jv-convert \
	  /usr/bin/jcf-dump-$(PV_GCJ) /usr/bin/jcf-dump \
	  /usr/bin/gcj-wrapper-$(PV_GCJ) /usr/bin/gcj-wrapper \
	  /usr/bin/gtnameserv-$(PV_GCJ) /usr/bin/gtnameserv \
	  /usr/bin/gappletviewer-$(PV_GCJ) /usr/bin/gappletviewer \
	  /usr/share/java/libgcj-$(PV_GCJ).jar /usr/share/java/libgcj.jar \
	  /usr/lib/pkgconfig/$(LIBGCJ_PC) /usr/lib/pkgconfig/libgcj.pc

	dh_link -pgcj-jre-headless \
	  /usr/share/man/man1/gkeytool-$(PV_GIJ).1.gz /usr/share/man/man1/gkeytool.1.gz \
	  /usr/share/man/man1/gorbd-$(PV_GIJ).1.gz /usr/share/man/man1/gorbd.1.gz \
	  /usr/share/man/man1/grmid-$(PV_GIJ).1.gz /usr/share/man/man1/grmid.1.gz \
	  /usr/share/man/man1/grmiregistry-$(PV_GIJ).1.gz /usr/share/man/man1/grmiregistry.1.gz \
	  /usr/share/man/man1/gserialver-$(PV_GIJ).1.gz /usr/share/man/man1/gserialver.1.gz

	dh_link -pgcj-jdk \
	  /usr/share/man/man1/gjar-$(PV_GCJ).1.gz /usr/share/man/man1/gjar.1.gz \
	  /usr/share/man/man1/gjarsigner-$(PV_GCJ).1.gz /usr/share/man/man1/gjarsigner.1.gz \
	  /usr/share/man/man1/gjavah-$(PV_GCJ).1.gz /usr/share/man/man1/gjavah.1.gz \
	  /usr/share/man/man1/gnative2ascii-$(PV_GIJ).1.gz /usr/share/man/man1/gnative2ascii.1.gz \
	  /usr/share/man/man1/gtnameserv-$(PV_GCJ).1.gz /usr/share/man/man1/gtnameserv.1.gz \
	  /usr/share/man/man1/gappletviewer-$(PV_GCJ).1.gz /usr/share/man/man1/gappletviewer.1.gz

  ifeq ($(with_gfdl_docs),yes)
	dh_link -pgcj-jre-headless \
	  /usr/share/man/man1/gij-$(PV_GIJ).1.gz /usr/share/man/man1/gij.1.gz \
	  /usr/share/man/man1/gcj-dbtool-$(PV_GIJ).1.gz /usr/share/man/man1/gcj-dbtool.1.gz
	dh_link -pgcj-jdk \
	  /usr/share/man/man1/gcj-$(PV_GCJ).1.gz /usr/share/man/man1/gcj.1.gz \
	  /usr/share/man/man1/gcj-$(PV_GCJ).1.gz /usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-gcj.1.gz \
	  /usr/share/man/man1/gcjh-$(PV_GCJ).1.gz /usr/share/man/man1/gcjh.1.gz \
	  /usr/share/man/man1/grmic-$(PV_GCJ).1.gz /usr/share/man/man1/grmic.1.gz \
	  /usr/share/man/man1/jv-convert-$(PV_GCJ).1.gz /usr/share/man/man1/jv-convert.1.gz \
	  /usr/share/man/man1/jcf-dump-$(PV_GCJ).1.gz /usr/share/man/man1/jcf-dump.1.gz \
	  /usr/share/man/man1/gcj-wrapper-$(PV_GCJ).1.gz /usr/share/man/man1/gcj-wrapper.1.gz \
	  /usr/share/info/gcj-$(PV_GCJ).info.gz /usr/share/info/gcj.info.gz
  endif

#  ifneq (,$(filter $(DEB_HOST_ARCH), $(gcj44_archs)))
	dh_link -pgcj-jdk \
	  /usr/bin/gjdoc-$(PV_GCJ) /usr/bin/gjdoc \
	  /usr/share/man/man1/gjdoc-$(PV_GCJ).1.gz /usr/share/man/man1/gjdoc.1.gz
	cp -p debian/dh_javadoc debian/gcj-jdk/usr/bin/
	pod2man -c Debhelper -r $(PV_GCJ) \
		debian/dh_javadoc debian/gcj-jdk/usr/share/man/man1/dh_javadoc.1
# endif

	: # libgcj-bc
	dh_installdirs -plibgcj-bc \
		usr/lib usr/share/doc usr/share/lintian/overrides
	dh_link -plibgcj-bc \
	  /usr/share/doc/libgcj-common /usr/share/doc/libgcj-bc
	ln -s libgcj.so.$(LIBGCJ_SONAME) \
		debian/libgcj-bc/usr/lib/libgcj_bc.so.1

	mkdir -p debian/libgcj-bc/usr/share/lintian/overrides
	cp -p debian/libgcj-bc.overrides \
		debian/libgcj-bc/usr/share/lintian/overrides/libgcj-bc

	echo "libgcj_bc 1 libgcj-bc $(REQV_LIBGCJ_BC)" \
		> debian/libgcj-bc.shlibs
#	echo "libgcj_bc 1 libgcj-bc" > debian/libgcj-bc.shlibs

#  ifneq (,$(filter $(DEB_HOST_ARCH), $(gcj44_archs)))
	: # gcj-jre-headless
	dh_installdirs -pgcj-jre-headless \
		usr/share/doc usr/lib/jvm
#	ln -sf java-1.5.0-gcj-$(PV_GCJ)-1.5.0.0 \
#		debian/gcj-jre-headless/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0
	ln -sf java-1.5.0-gcj-$(PV_GCJ) \
		debian/gcj-jre-headless/usr/lib/jvm/java-1.5.0-gcj
	ln -sf java-gcj-$(PV_GCJ) \
		debian/gcj-jre-headless/usr/lib/jvm/java-gcj
#  endif
endif

	: # libgcj-common
	dh_installdirs -plibgcj-common \
	  /usr/bin \
	  /usr/sbin \
	  /etc/java/security/security.d \
	  /usr/lib/security \
	  /var/lib/security \
	  /usr/share/gcj
	install -m644 classpath.security debian/libgcj-common/etc/java/security/
	dh_link -plibgcj-common \
	  /var/lib/security/classpath.security /usr/lib/security/classpath.security
	install -m755 debian/rebuild-gcj-db \
		debian/libgcj-common/usr/bin/
	install -m755 debian/rebuild-security-providers \
		debian/libgcj-common/usr/sbin/
	( \
	  echo "# architectures with gcj support"; \
	  echo "gcj_archs = $(gcj_archs)"; \
	  echo "# architectures which should provide gcj native support"; \
	  echo "gcj_native_archs = $(gcj_native_archs)" \
	) > debian/libgcj-common/usr/share/gcj/debian_defaults

	: # GNU security provider
	for i in \
	  1000-gnu.java.security.provider.Gnu \
	  1001-gnu.javax.crypto.jce.GnuCrypto \
	  1002-gnu.javax.crypto.jce.GnuSasl \
	  1003-gnu.javax.net.ssl.provider.Jessie \
	  1004-gnu.javax.security.auth.callback.GnuCallbacks; \
	do \
	  touch debian/libgcj-common/etc/java/security/security.d/$$i; \
	done

	: # aotcompile & dh_nativejava

	mkdir -p debian/libgcj-common/usr/bin
	install -m755 debian/aot-compile debian/libgcj-common/usr/bin/
	mkdir -p debian/libgcj-common/usr/lib/gcc
	install -m644 debian/*.py debian/libgcj-common/usr/lib/gcc

	install -m755 debian/dh_nativejava debian/libgcj-common/usr/bin/
	mkdir -p debian/libgcj-common/usr/share/debhelper/autoscripts
	install -m 644 debian/p*-rebuild-gcj-db \
		debian/libgcj-common/usr/share/debhelper/autoscripts/
	pod2man -c Debhelper debian/dh_nativejava debian/dh_nativejava.1
	mkdir -p debian/libgcj-common/usr/share/man/man1
	install -m644 debian/dh_nativejava.1 debian/libgcj-common/usr/share/man/man1/

ifneq (,$(filter gpc, $(packages)))
	: # gpc
	dh_installdirs -pgpc usr/bin /usr/share/man/man1 usr/share/doc
	dh_link -pgpc \
	  /usr/share/doc/cpp /usr/share/doc/gpc \
	  /usr/bin/gpc-$(PV_GPC) /usr/bin/gpc \
	  /usr/share/man/man1/gpc-$(PV_GPC).1.gz /usr/share/man/man1/gpc.1.gz \
	  /usr/bin/gpc-run-$(PV_GPC) /usr/bin/gpc-run \
	  /usr/share/man/man1/gpc-run-$(PV_GPC).1.gz /usr/share/man/man1/gpc-run.1.gz \
	  /usr/bin/binobj-$(PV_GPC) /usr/bin/binobj \
	  /usr/share/man/man1/binobj-$(PV_GPC).1.gz /usr/share/man/man1/binobj.1.gz \
	  /usr/bin/gpidump-$(PV_GPC) /usr/bin/gpidump \
	  /usr/share/man/man1/gpidump-$(PV_GPC).1.gz /usr/share/man/man1/gpidump.1.gz

	: # gpc-doc
	dh_installdirs -pgpc-doc \
		usr/share/doc usr/share/info
	dh_link -pgpc-doc \
	  /usr/share/info/gpc-$(PV_GPC).info.gz /usr/share/info/gpc.info.gz \
	  /usr/share/info/gpcs-$(PV_GPC).info.gz /usr/share/info/gpcs.info.gz \
	  /usr/share/info/gpcs-de-$(PV_GPC).info.gz /usr/share/info/gpcs-de.info.gz \
	  /usr/share/info/gpcs-hu-$(PV_GPC).info.gz /usr/share/info/gpcs-hu.info.gz
endif

ifneq (,$(filter gcc-spu, $(packages)))
	: # gcc-spu
	dh_installdirs -pgcc-spu \
	  usr/share/doc usr/bin

	dh_link -pgcc-spu \
		/usr/bin/spu-cpp-$(PV_SPU) /usr/bin/spu-cpp \
		/usr/bin/spu-gcc-$(PV_SPU) /usr/bin/spu-gcc
endif
ifneq (,$(filter g++-spu, $(packages)))
	: # g++-spu
	dh_installdirs -pg++-spu \
	  usr/share/doc usr/bin

	dh_link -pg++-spu \
		/usr/bin/spu-g++-$(PV_SPU) /usr/bin/spu-g++
endif
ifneq (,$(filter gfortran-spu, $(packages)))
	: # gfortran-spu
	dh_installdirs -pgfortran-spu \
	  usr/share/doc usr/bin

	dh_link -pgfortran-spu \
		/usr/bin/spu-gfortran-$(PV_SPU) /usr/bin/spu-gfortran
endif

nopkgs :=-s $(foreach p, $(no_packages),-N$(p))

cacerts-stamp:
	dh_testdir
	rm -rf build
	mkdir -p build
	sed 's/@gcc_suffix@//' debian/generate-cacerts.pl.in \
		> debian/generate-cacerts.pl
	cd build && perl ../debian/generate-cacerts.pl \
		/etc/ssl/certs/ca-certificates.crt
	touch $@

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -i

	dh_installdocs -plibgcj-common
	dh_installchangelogs -plibgcj-common
	#mv debian/libgcj-common/usr/share/doc/libgcj-common/changelog \
	#	debian/libgcj-common/usr/share/doc/libgcj-common/changelog.Debian

	#install -m644 build/cacerts debian/libgcj-common/etc/java/cacerts-gcj

	dh_compress -i -XREADME.Debian
	dh_fixperms -i
	dh_pycentral -plibgcj-common
	dh_installdeb -i
	dh_gencontrol -plibgcj-common -u-v$(CV_LIBGCJCOMMON)
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs -pcpp
	for p in `dh_listpackages $(nopkgs) -Ncpp -Ncpp-doc -Ngcc-doc -Ngpc-doc -Ngfortran-doc -Ngdc`; do \
	  case "$$p" in gij|gcj-*) t=libgcj-common;; *) t=cpp; esac; \
	  echo ln -sf $$t debian/$$p/usr/share/doc/$$p; \
	  mkdir -p debian/$$p/usr/share/doc; \
	  rm -f debian/$$p/usr/share/doc/$$p; \
	  ln -sf $$t debian/$$p/usr/share/doc/$$p; \
	done

	dh_installchangelogs -pcpp -pgdc
	#mv debian/cpp/usr/share/doc/cpp/changelog \
	#	debian/cpp/usr/share/doc/cpp/changelog.Debian
	#mv debian/gdc/usr/share/doc/gdc/changelog \
	#	debian/gdc/usr/share/doc/gdc/changelog.Debian
ifneq (,$(filter gpc, $(packages)))
	dh_installdocs -pgpc-doc
	dh_installchangelogs -pgpc-doc
	#mv debian/gpc-doc/usr/share/doc/gpc-doc/changelog \
	#	debian/gpc-doc/usr/share/doc/gpc-doc/changelog.Debian
endif
ifeq ($(with_gfdl_docs),yes)
	dh_installdocs -pcpp-doc -pgcc-doc -pgfortran-doc
	dh_installchangelogs -pcpp-doc -pgcc-doc -pgfortran-doc
endif
	dh_compress -s $(nopkgs) -XREADME.Debian
	dh_fixperms -s $(nopkgs)
	dh_installdeb -s $(nopkgs)
	dh_gencontrol -pcpp     -u-v$(EPOCH):$(CV_CPP)
	dh_gencontrol -pgcc     -u-v$(EPOCH):$(CV_GCC)
  ifeq ($(with_multilib),yes)
	dh_gencontrol -pgcc-multilib -u-v$(EPOCH):$(CV_GCC)
  endif
  ifeq ($(with_gfdl_docs),yes)
	dh_gencontrol -pcpp-doc -u-v$(EPOCH):$(CV_CPP)
	dh_gencontrol -pgcc-doc -u-v$(EPOCH):$(CV_GCC)
  endif
ifneq (,$(filter gdc, $(packages)))
	dh_gencontrol -pgdc -u-v$(CV_GDC)
endif
ifneq (,$(filter g++, $(packages)))
	dh_gencontrol -pg++     -u-v$(EPOCH):$(CV_GPP)
  ifeq ($(with_multilib),yes)
	dh_gencontrol -pg++-multilib -u-v$(EPOCH):$(CV_GPP)
  endif
endif
ifneq (,$(filter gobjc, $(packages)))
	dh_gencontrol -pgobjc   -u-v$(EPOCH):$(CV_GOBJC)
  ifeq ($(with_multilib),yes)
	dh_gencontrol -pgobjc-multilib -u-v$(EPOCH):$(CV_GOBJC)
  endif
endif
ifneq (,$(filter gobjc++, $(packages)))
	dh_gencontrol -pgobjc++   -u-v$(EPOCH):$(CV_GOBJCXX)
  ifeq ($(with_multilib),yes)
	dh_gencontrol -pgobjc++-multilib -u-v$(EPOCH):$(CV_GOBJCXX)
  endif
endif
ifneq (,$(filter gfortran, $(packages)))
	dh_gencontrol -pgfortran     -u-v$(EPOCH):$(CV_GFORT)
  ifeq ($(with_multilib),yes)
	dh_gencontrol -pgfortran-multilib -u-v$(EPOCH):$(CV_GFORT)
  endif
  ifeq ($(with_gfdl_docs),yes)
	dh_gencontrol -pgfortran-doc -u-v$(EPOCH):$(CV_GFORT)
  endif
endif
ifneq (,$(filter gpc, $(packages)))
	dh_gencontrol -pgpc     -u-v$(EPOCH_GPC):$(CV_GPC)
	dh_gencontrol -pgpc-doc -u-v$(EPOCH_GPC):$(CV_GPC)
endif
ifneq (,$(filter gcj, $(packages)))
	dh_gencontrol -pgcj         -u-v$(EPOCH):$(CV_GCJ)
	dh_gencontrol -pgij         -u-v$(EPOCH):$(CV_GIJ)
	dh_gencontrol -plibgcj-bc   -u-v$(CV_LIBGCJBC)

	dh_gencontrol -pgcj-jre-headless -pgcj-jre -pgcj-jdk \
		-u-v$(EPOCH):$(CV_GCJ)
endif
ifneq (,$(filter chill, $(packages)))
	dh_gencontrol -pchill -u-v$(EPOCH):$(CV_CHILL)
endif
ifneq (,$(filter gcc-spu, $(packages)))
	dh_gencontrol -pgcc-spu -u-v$(CV_SPU)
endif
ifneq (,$(filter g++-spu, $(packages)))
	dh_gencontrol -pg++-spu -u-v$(CV_SPU)
endif
ifneq (,$(filter gfortran-spu, $(packages)))
	dh_gencontrol -pgfortran-spu -u-v$(CV_SPU)
endif
	dh_md5sums -s $(nopkgs)
	dh_builddeb -s $(nopkgs)

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
